<script>
/**
 * Orders Component
 */
export default {
  data() {
    return {
      title: "Orders",
      items: [
        {
          text: "Ecommerce",
        },
        {
          text: "Orders",
          active: true,
        },
      ],
      ordersData: [
        {
          time: "刚刚",
          rang: "信息",
          applicationId: "SSPiDER_04_2021_08_1057",
          applicationName: "靖江市政府采购平台_最新公告",
          runtimeEnvironment:"测试",
          execution:"192.168.71.32",
          type:"招标信源",
          daily:"INFO  org.HttpAnalysis -请求成功"
        },{
          time: "刚刚",
          rang: "错误",
          applicationId: "SSPiDER_05_2022_01_157",
          applicationName: "南京玄武外国语学校_通知通告",
          runtimeEnvironment:"正式",
          execution:"10.0.71.52",
          type:"招标信源",
          daily:"ERROR cn.edu.hfut.ContentExtractor - 抓取出错"
        },{
          time: "刚刚",
          rang: "错误",
          applicationId: "SSPiDER_04_2021_07_1255",
          applicationName: "江苏省教育考试院_招考要闻",
          runtimeEnvironment:"测试",
          execution:"192.168.71.53",
          type:"资讯信源",
          daily:"ERROR java.lang.NullPointerException: 空指针异常"
        },{
          time: "1分钟前",
          rang: "信息",
          applicationId: "SSPiDER_02_2020_07_876",
          applicationName: "PT塑料网_电子电气",
          runtimeEnvironment:"测试",
          execution:"10.0.71.64",
          type:"资讯信源",
          daily:"INFO  org.HttpAnalysis -请求成功"
        },{
          time: "2分钟前",
          rang: "错误",
          applicationId: "SSPiDER_09_2018_12_1920",
          applicationName: "第一财经_新闻",
          runtimeEnvironment:"正式",
          execution:"192.168.71.72",
          type:"资讯信源",
          daily:"ERROR java.IllegalArgumentException: URL地址无效"
        },{
          time: "2分钟前",
          rang: "信息",
          applicationId: "SSPiDER_04_2019_11_7829",
          applicationName: "证券之星_板块掘金",
          runtimeEnvironment:"正式",
          execution:"10.0.71.55",
          type:"资讯信源",
          daily:"INFO  org.HttpAnalysis -请求成功"
        },{
          time: "2分钟前",
          rang: "信息",
          applicationId: "SSPiDER_05_2021_12_3571",
          applicationName: "东方财富网_外汇导读",
          runtimeEnvironment:"正式",
          execution:"10.0.71.22",
          type:"资讯信源",
          daily:"INFO  org.HttpAnalysis -请求成功"
        },{
          time: "3分钟前",
          rang: "信息",
          applicationId: "SSPiDER_02_2022_01_1982",
          applicationName: "财经界_热点",
          runtimeEnvironment:"测试",
          execution:"10.0.71.21",
          type:"热点信源",
          daily:"INFO  org.util.HttpAnalysis -请求成功"
        },{
          time: "3分钟前",
          rang: "警告",
          applicationId: "SSPiDER_02_2018_04_123",
          applicationName: "全球经济数据网_最新文章",
          runtimeEnvironment:"正式",
          execution:"10.0.71.34",
          type:"资讯信源",
          daily:"DEBUG o.s.core.ExecuteSQLExecutor - 执行sql"
        },{
          time: "4分钟前",
          rang: "警告",
          applicationId: "SSPiDER_07_2019_01_37182",
          applicationName: "每日经济网_金融",
          runtimeEnvironment:"正式",
          execution:"192.168.71.32",
          type:"资讯信源",
          daily:"DEBUG o.s.core.ExecuteSQLExecutor - 执行sql"
        }
      ],
      totalRows: 100,
      currentPage: 1,
      perPage: 10,
      fields: [
        { key: "daily", label: "日志摘要" },
        { key: "rang",  label: "日志等级" },
        { key: "applicationId",  label: "应用ID" },
        { key: "applicationName", label: "应用名称" },
        { key: "runtimeEnvironment", label: "运行环境" },
        { key: "execution",  label: "执行服务器" },
        { key: "type",  label: "信源类型" },
        { key: "time", label: "日志时间" },
      ],
      dropdownSel: '日志查看',
    };
  },
  watch: {
    "currentPage": {
      handler(){
        console.log("触发更新");
      }
    }
  },
  methods: {
    /**
     * Search the table data with search input
     */
    onFiltered(filteredItems) {
      // Trigger pagination to update the number of buttons/pages due to filtering
      this.totalRows = filteredItems.length;
      this.currentPage = 1;
    },
    changeRefresh(v){
      this.dropdownSel = v;
    },
    toDetail(item){
      console.log(item);
      this.$router.push('/log/pageDetail')
    },
  },
};
</script>

<template>
  <div>
    <!-- 搜索 -->
    <div class="search-box">
      <div class="searchNum">为您搜索到<span>5,000+</span>条日志信息</div>
      <div>
        <b-dropdown variant="secondary" class="butn">
          <template slot="button-content">
            <i class="ri-add-line align-middle" style="font-size: 1rem;"></i>
            <span style="margin:0 20px 0 6px;">{{dropdownSel}}</span>
            <i class="mdi mdi-chevron-down"></i>
          </template>
          <b-dropdown-item-button @click="changeRefresh('10秒刷新')">10秒刷新</b-dropdown-item-button>
          <b-dropdown-item-button @click="changeRefresh('5秒刷新')">5秒刷新</b-dropdown-item-button>
          <b-dropdown-item-button @click="changeRefresh('2秒刷新')">2秒刷新</b-dropdown-item-button>
          <b-dropdown-item-button @click="changeRefresh('不刷新')">不刷新</b-dropdown-item-button>
        </b-dropdown>
      </div>
    </div>

    <div class="table-responsive">
      <b-table
        class="table-centered"
        :items="ordersData"
        :fields="fields"
        responsive="sm"
        :per-page="perPage"
        :current-page="1"
        thead-class="thead-light"
        @filtered="onFiltered"
      >
        <template v-slot:cell(daily)="row">
          <div class="pointer" style="color: #5664d2;" @click="toDetail(row.item)">{{ row.value}}</div>
        </template>
        <template v-slot:cell(rang)="row">
          <div v-if="row.value=='信息'" class="badge font-size-12 badge-soft-success">{{ row.value}}</div>
          <div v-if="row.value=='错误'" class="badge font-size-12 badge-soft-danger">{{ row.value}}</div>
          <div v-if="row.value=='警告'" class="badge font-size-12 badge-soft-warning">{{ row.value}}</div>
        </template>
        <template v-slot:cell(runtimeEnvironment)="row">
          <div v-if="row.value=='正式'" class="badge font-size-12 badge-soft-primary">{{ row.value}}</div>
          <div v-if="row.value=='测试'" class="badge font-size-12 badge-soft-info">{{ row.value}}</div>
        </template>
      </b-table>
    </div>
    <div class="row">
      <div class="col">
        <div class="dataTables_paginate paging_simple_numbers float-right">
          <ul class="pagination pagination-rounded mb-0">
            <!-- pagination -->
            <b-pagination
              v-model="currentPage"
              :total-rows="totalRows"
              :per-page="perPage"
            ></b-pagination>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.search {
  float: left;
  width: 300px;
  margin-bottom: 20px;
}
.butn{
  ::v-deep .btn{
    background-color: #252b3b;
    border-color: #252b3b;
    border-radius: 30px;
    display: flex;
    align-items: center;
  }
  ::v-deep .btn-secondary.focus {
    box-shadow: 0 0 0 0.15rem rgb(37 40 58 / 50%);
  }
}
.search-box{
  padding: 20px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.searchNum{
  span{
    font-size: 1rem;
    color: #3444c1;
    margin: 0 4px;
    font-weight: 600;
  }
}
.table-centered{
  ::v-deep thead,::v-deep tbody{
    tr{
      th:last-child,td:last-child{
        text-align: right;
      }
    }
  }
}
</style>
 

